#!/sbin/openrc-run

name="Gerbera"
configfile="${CONFIG:-/etc/gerbera/config.xml}"
start_stop_daemon_args="--user ${G_USER:-gerbera} --group ${G_GROUP:-gerbera}"
pidfile="/run/gerbera/gerbera.pid"
command=/usr/bin/gerbera
command_args="-c $configfile -l /var/log/gerbera/gerbera.log"
command_background=true

depend() {
	need net
}

start_pre() {
	if ! [ -f "${configfile}" ]; then
		/usr/sbin/gerbera --create-config > "${configfile}"
	fi
	if yesno "${DEBUG}"; then
		command_args="$command_args -D"
	fi
	if [ ! -z "${BIND_INTERFACE}" ]; then
		command_args="$command_args -e ${BIND_INTERFACE}"
	fi
	if [ ! -z "${BIND_PORT}" ]; then
		command_args="$command_args -p ${BIND_PORT}"
	fi
	if [ ! -z "${BIND_IP}" ]; then
		command_args="$command_args -i ${BIND_IP}"
	fi
	
	checkpath --owner ${G_USER:-gerbera}:${G_GROUP:-gerbera} \
		--directory ${pidfile%/*}
}
